﻿using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;
using Rites;

namespace Rites.UI
{
    public class UIManager
    {
        private SpriteFont ChatFont;
        public UIChatbox Chatbox { get; set; }
        public UIChatbox InteractiveBox { get; set; }
        public UIMouseHandler MouseHandler { get; set; }
        public string PlayerName{ get; set; }
       
        public UIManager()
        {
        }

        public void LoadContent(ContentManager content)
        {
            ChatFont = content.Load<SpriteFont>("Fonts//RitesChat");
            Chatbox.LoadContent(content);
            InteractiveBox.LoadContent(content);
            MouseHandler.LoadContent(content);
        }

        //TODO: We should pass the player object in, not just the name - will get to that
        public void InitUI(GraphicsDeviceManager gdm, TextEventDelegate chatEvent, string plrName)
        {
            int chatWidth = (int)(gdm.PreferredBackBufferWidth * 0.50);
            int chatHeight = (int)(gdm.PreferredBackBufferHeight / 4);
            int chatTop = gdm.PreferredBackBufferHeight - chatHeight;

            Chatbox = new UIChatbox(0, chatTop, chatWidth, chatHeight, Constants.KEYBOARD_BUFFERSIZE);
            Chatbox.TextCommand += new TextEventDelegate(chatEvent);
            Chatbox.PlayerName = plrName;

            InteractiveBox = new UIChatbox(512, chatTop, chatWidth, chatHeight, 0);
            InteractiveBox.PlayerName = plrName;

            PlayerName = plrName;
            MouseHandler = new UIMouseHandler();
         }

        public void HandleInput(InputHandler inputHandler)
        {
            MouseHandler.Update();
            Chatbox.HandleInput(inputHandler);
        }

        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            Chatbox.Draw(spriteBatch);
            InteractiveBox.Draw(spriteBatch);

            MouseHandler.Draw(spriteBatch);
        }
    }
}